//
//  YW_CommonTool.swift
//  demo02
//
//  Created by 陈友文 on 2021/1/27.
//

import UIKit
//import SnapKit

let kUserDateIcon = "user_icon"
let kUserDateName = "user_name"
let kUserDateSex = "user_sex"
let kUserDateLogin = "user_login"
let kUserDateId = "user_id"
let kUserDateAge = "user_age"
let kUserBindId = "user_bind_id"
let kUserToken = "user_token"
let kUserIconBase64 = "user_icon_base64"


/*
通知相关
 */


/*
 订阅相关
 */
let kPurchaseName = "lulemevip"



/*
 app key相关
*/
let kAPPId = "6670193573"
let kVipKey = "k_luleme_vip"


/* 屏幕相关 */
/// 屏幕
let kScreenBounds   = UIScreen.main.bounds
/// 屏幕宽
let kScreenWidth    = UIScreen.main.bounds.width
/// 屏幕高
let kScreenHeight   = UIScreen.main.bounds.height

/* 设备系统相关  */
let kiOSVersion:String        = UIDevice.current.systemVersion         /* iOS系统版本 */
let kosType:String             = UIDevice.current.systemName + UIDevice.current.systemVersion

/* app版本  以及设备系统版本 */
let infoDictionary            = Bundle.main.infoDictionary
let kAppName: String?         = infoDictionary!["CFBundleDisplayName"] as? String        /* App名称 */
let kAppVersion: String?      = infoDictionary!["CFBundleShortVersionString"] as? String /* App版本号 */
let kAppBuildVersion: String? = infoDictionary!["CFBundleVersion"] as? String            /* Appbuild版本号 */
let kAppBundleId: String?     = infoDictionary!["CFBundleIdentifier"] as? String                 /* app bundleId */
let kPlatformName: String?     = infoDictionary!["DTPlatformName"] as? String  //平台名称（iphonesimulator 、 iphone）

let Width_Ratio6 = kScreenWidth / 375.0
let Height_Ratio6 = (kScreenHeight / 667.0 >= 1 ? 1 : kScreenHeight / 667.0)

/* iPhonex以上判断 */
let kIsIPhoneXAll       = (kScreenHeight >= 780)
//导航栏高
let kNaviHeight         = (kIsIPhoneXAll ? UIApplication.shared.statusBarFrame.height + 44 : 64)
//状态栏高
let kStateHeight        = (kIsIPhoneXAll ? 44 : 20)
//选项卡高
let kTabbarHeight       = (kIsIPhoneXAll ? 83 : 49)
//安全区高
let kSafeBottomHeight   = (kIsIPhoneXAll ? 34 : 0)
//屏幕宽高比
let kAspectRatio        = kScreenWidth / kScreenHeight

// pickerView高
let kPickerViewHeight = 276

/**
 颜色相关
 */




/* debugPrint */
func DPrint (_ item : Any){
   //#if DEBUG
       print(item)
  // #endif
}

/* 命名空间 */
extension Bundle{
    func namespace() -> String {
        return Bundle.main.infoDictionary?["CFBundleName"]  as? String ?? ""
    }
}


/* 适配xib layer中的颜色 */
extension CALayer{
    @IBInspectable var borderColorWithUIColor: UIColor {
         get {
             return UIColor(cgColor: self.borderColor!)
         }
         set {
             self.borderColor = newValue.cgColor
         }
    }
    
    @IBInspectable var shadowColorWithUIColor: UIColor {
         get {
             return UIColor(cgColor: self.shadowColor!)
         }
         set {
             self.shadowColor = newValue.cgColor
         }
    }

}


extension NSObject{
    //生成二维码
    func generateQRCode(str: String) -> UIImage? {
        let data = str.data(using: String.Encoding.utf8)
        guard let filter = CIFilter(name: "CIQRCodeGenerator") else { return nil }
        filter.setValue(data, forKey: "inputMessage")
        let transform = CGAffineTransform(scaleX: 9, y: 9)
        guard let output = filter.outputImage?.transformed(by: transform) else { return nil }
        return UIImage(ciImage: output)
    }
    
    
    func drawQRCode(orginalImage:UIImage) -> UIImage? {
        let scaleW = orginalImage.size.width
        let scaleH = orginalImage.size.height
        let scaleSize = CGSize(width: scaleW, height: scaleH)
        UIGraphicsBeginImageContext(scaleSize)
        orginalImage.draw(in: CGRect(x: 0, y: 0, width: scaleW, height: scaleH))
        let newImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return newImage
    }
}


